package ben.samplegame.sprite;

import java.awt.Image;
import java.awt.Point;
import java.awt.Shape;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import javax.imageio.ImageIO;
import ben.samplegame.collision.EnemyCollisionBehavior;
import game.physics.GameVector;
import game.physics.ImpulseVector;
import game.sprite.MovableSprite;
import game.sprite.PlayerSprite;
import game.sprite.collision.CollisionBehavior;
import game.sprite.collision.ICollidable;

public class SampleEnemy extends MovableSprite implements ICollidable {

    private final String STANDARD_STATE = "standard_state";
    private CollisionBehavior myCollisionBehavior;
    private PlayerSprite myPlayer;
    
    public SampleEnemy (Point startLocation, String spriteSet, boolean isActive, PlayerSprite player) {
        super(startLocation, spriteSet, isActive);
        myPlayer = player;
        myCollisionBehavior = new EnemyCollisionBehavior(this);
        HashMap<String, Image> tempSpriteSet = new HashMap<String, Image>();
        Image testImage = null;
        try {
            testImage = ImageIO.read(new File("src/ben/samplegame/resources/space_monster.png"));

        } catch (IOException e) {
        }
        
        tempSpriteSet.put(STANDARD_STATE, testImage);
        setSpriteSet(tempSpriteSet);
        setActiveImage(STANDARD_STATE);
        setCenterCoordinate(startLocation);
        this.resize(.1);
    }

    @Override
    public void applyFriction () {
        getVelocity().multiply(.2);
        
    }

    @Override
    public void update () {
        move();
     ImpulseVector chaseForce = new ImpulseVector(getCenterCoordinate(), myPlayer.getCenterCoordinate(), .1);
     chaseForce = new ImpulseVector(chaseForce.getUnitVector(), .1);
     chaseForce.multiply(.01);
     addExternalForce(chaseForce);
     applyFriction();
     
        
    }

    @Override
    public void applyForce (GameVector force) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public Shape getOutline () {
        return getBounds();
    }

    @Override
    public CollisionBehavior getCollisionBehavior () {
        return myCollisionBehavior;
    }

    @Override
    public void setCollisionBehavior (CollisionBehavior collisionBehavior) {
        myCollisionBehavior = collisionBehavior;
        
    }

    @Override
    public void accept (ICollidable collidable) {
        collidable.getCollisionBehavior().visit(this);      
    }

}
